package com.elsa.smart_buffet.service.impl;

import com.elsa.smart_buffet.mapper.MenuIncomeExpenseMapper;
import com.elsa.smart_buffet.pojo.ResultBox.CallBackMessage;
import com.elsa.smart_buffet.pojo.ResultBox.ResponseResult;
import com.elsa.smart_buffet.pojo.po.MenuIncomeExpense;
import com.elsa.smart_buffet.pojo.vo.MenuIncomeExpenseStats;
import com.elsa.smart_buffet.service.MenuIncomeExpenseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : MenuIncomeExpenseServiceImpl  //类名
 * @Author : elsa //作者
 */
@Service
@Slf4j
@Transactional
public class MenuIncomeExpenseServiceImpl implements MenuIncomeExpenseService {

    @Autowired
    private MenuIncomeExpenseMapper menuIncomeExpenseMapper;

    @Override
    public ResponseResult getMenuIncomeExpenseByTime(String date) {

        List<MenuIncomeExpense> menuIncomeExpenseList = new ArrayList<>();
        List<MenuIncomeExpenseStats> menuIncomeExpenseStatsList = new ArrayList<>();
        menuIncomeExpenseList = menuIncomeExpenseMapper.getMenuIncomeExpenseByTime(date);
        for (int i = 0; i < menuIncomeExpenseList.size(); i++) {
            MenuIncomeExpenseStats menuIncomeExpenseStats = new MenuIncomeExpenseStats();
            MenuIncomeExpense menuIncomeExpense = menuIncomeExpenseList.get(i);
            menuIncomeExpenseStats.setId(menuIncomeExpense.getId());
            menuIncomeExpenseStats.setName(menuIncomeExpense.getName());
            menuIncomeExpenseStats.setNum(menuIncomeExpense.getNum());
            menuIncomeExpenseStats.setIncome(menuIncomeExpense.getIncome());
            menuIncomeExpenseStats.setExpand(menuIncomeExpense.getExpand());
            menuIncomeExpenseStats.setPrice(menuIncomeExpense.getPrice());
            menuIncomeExpenseStats.setProfit(menuIncomeExpense.getProfit());
            menuIncomeExpenseStats.setLook(menuIncomeExpense.getLook());
            menuIncomeExpenseStats.setState("已上架");
            menuIncomeExpenseStatsList.add(menuIncomeExpenseStats);
        }
        log.info(String.valueOf(menuIncomeExpenseStatsList));
        return new ResponseResult(CallBackMessage.SUCCESS, menuIncomeExpenseStatsList);
    }
}
